import React, {useState, useEffect} from "react";
import './index.scss'
import {Form, Input, message, Modal} from "antd";
import {useDispatch, useSelector} from "react-redux";
import {storeSetSettingVisible} from "../../store/store.js";
import RendererAppUtil from "../../util/RendererAppUtil.js";
import TextareaObj from "../TextareaObj/index.jsx";


export default function ({}) {
  const dispatch = useDispatch()
  const storeSettingVisible = useSelector(state => state.settingVisible)
  const [config, setConfig] = useState({})

  useEffect(() => {
    if (storeSettingVisible) {
      let res = RendererAppUtil.getElectronRemoteApp().AppUtil.getConfig();
      console.log(res)
    }
  }, [storeSettingVisible]);

  return <Modal
    title={'项目设置'}
    open={storeSettingVisible}
    className={'AppSetting'}
    onOk={e => {
      RendererAppUtil.getElectronRemoteApp().AppUtil.setConfig(config);
      dispatch(storeSetSettingVisible(false))
    }}
    onCancel={e => {
      console.log('onClose')
      dispatch(storeSetSettingVisible(false))
    }}>
    <Form
      labelCol={{
        span: 4
      }}
      wrapperCol={{
        span: 20
      }}
    >
      <Form.Item label={'工作目录'}>
        <TextareaObj
          value={config}
          onBlur={e => {
            setConfig(e)
          }}/>
      </Form.Item>
    </Form>
  </Modal>
}